<!DOCTYPE HTML>
<%@page import="shop.vo.UserBean"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="shop.vo.AddressBean"%>
<%@page import="shop.factory.DAOFactory"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<meta charset="UTF-8" />
<link rel="stylesheet" href="../css/bootstrap.min.css">
<script src="../js/jquery-1.10.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>

<title>查看地址簿</title>
<style type="text/css">
th, td {
	text-align: center;
}
a {
	text-decoration: none;
	color: #00CCFF;
}

a:hover {
	color: red;
}
</style>
</head>
<%
	if (!(boolean)session.getAttribute("adminLogin")) {
		String path = request.getContextPath() + "/Admin/login.jsp";
		response.sendRedirect(path);
	}
%>
<body>
	<div class="container-fluid">
		<h3>用户的地址簿</h3>
		<div class="page-header" style="margin-top: 10px;"></div>
		<form action="<%=request.getContextPath()%>/AddressServlet"
			method="post">
			<input type="hidden" name="action" value="Admindelete">
			<table class="table table-bordered table-condensed table-striped">
				<thead>
					<tr>
						<th>多选</th>
						<th>序号</th>
						<th>用户姓名</th>
						<th>收货人姓名</th>
						<th>收货地址邮编</th>
						<th>收货人手机号</th>
						<th>收货地址</th>
					</tr>
				</thead>
				<tbody>
					<%
						int nowPage = 1;
						int pageSize = 10;
						String str = request.getParameter("to");
						if (str != null) {
							nowPage = Integer.parseInt(str);
						}
						int up = nowPage;
						int next = nowPage;
						int maxPage = 0;
						int count = DAOFactory.getIAddressDAOInstance().getCount();
						if (count % pageSize == 0) {
							maxPage = count / pageSize;
						} else {
							maxPage = (count / pageSize) + 1;
						}
						if (next < maxPage) {
							next += 1;
						}
						if (up > 1) {
							up -= 1;
						}
						List<AddressBean> list = DAOFactory.getIAddressDAOInstance().list(
								nowPage, pageSize);
						Iterator<AddressBean> it = list.iterator();
						while (it.hasNext()) {
							AddressBean addr = it.next();
							UserBean user = addr.getUser();
					%>

					<tr>
						<td><input type="checkbox" value="<%=addr.getAddr_id()%>"
							id="cheboxId" name="cheboxId"></td>
						<td><%=addr.getAddr_id()%></td>
						<td><%=user.getUser_name()%></td>
						<td><%=addr.getAddr_name()%></td> 
						<td><%=addr.getAddr_zip()%></td>
						<td><%=addr.getAddr_mobile()%></td>
						<td><%=addr.getAddr_address()%></td>
					</tr>
					<%
						}
					%>
					<tr>
						<td colspan="12"><input type="button" value="全选"
							onclick="quan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="button" value="反选" onclick="fan()">&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="reset" value="重置">&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="submit" value="删除" onclick="return confirm('是否删除？')"></td>
					</tr>

					<tr>
						<td colspan="12"><span class="style1"> <a
								href="addressList.jsp?to=1">首页</a>&nbsp;|&nbsp;
								<a href="addressList.jsp?to=<%=up%>">上一页</a>&nbsp;|&nbsp;<a
								href="addressList.jsp?to=<%=next%>">下一页</a>&nbsp;|&nbsp;
								<a href="addressList.jsp?to=<%=maxPage%>">尾页</a>
						</span> &nbsp;&nbsp;第&nbsp;<%=nowPage%>&nbsp;页/共&nbsp;<%=maxPage%>&nbsp;页
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	</div>
	<script type="text/javascript">
		function quan() {
			var checkObj = document.all("cheboxId");
			for (var i = 0; i < checkObj.length; i++) {
				checkObj[i].checked = true;
			}
		}
		function fan() {
			var checkObj = document.all("cheboxId");
			for (var i = 0; i < checkObj.length; i++) {
				if (checkObj[i].checked == true)
					checkObj[i].checked = false;
				else
					checkObj[i].checked = true;
			}
		}
	</script>
</body>
</html>